package com.keon.jianbao.util;

import android.content.Context;
import android.os.Message;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

/**
 * Created by keon on 15/10/28.
 */
public class CommonUtils {
    public static void share(Context context, String text, String url, String photopath, String sharename, PlatformActionListener platformActionListener) {
        Platform.ShareParams sp = new SinaWeibo.ShareParams();

        if (photopath != null) {
            // sp.imagePath = "/mnt/sdcard/测试分享的图片.jpg";
            sp.imagePath = photopath;
        }
        if (sharename == Wechat.NAME || sharename == WechatMoments.NAME) {
            sp.setShareType(Platform.SHARE_WEBPAGE);
            sp.setTitle(text);
            sp.setText(text);
            if (url != null) {
                sp.setUrl(url);
            }
        }
        if (sharename == SinaWeibo.NAME || sharename == QQ.NAME) {
            if (url != null) {
                sp.text = text + ":" + url;
            } else {
                sp.text = text;
            }

        }
        Platform weibo = ShareSDK.getPlatform(context, sharename);
        // 设置分享事件回调
        weibo.setPlatformActionListener(platformActionListener);


        // 执行图文分享
        weibo.share(sp);
    }
}
